package com.zfjt.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.zfjt.constants.InterfaceDefinition;
import com.zfjt.entity.ClientmessageBean;
import com.zfjt.entity.ReturnBean;
import com.zfjt.packnum.PackNum00017;
import com.zfjt.service.ClientmessageBeanService;

/**
 * 手续收取，权限为0可以设置
 * @author xk
 * @version 1.0
 * @date 2017年4月15日
 */
@Controller
public class OrderPoundageController {
	
	private ReturnBean mReturn;
	
	@Autowired
	private ClientmessageBeanService mClientMessage;
	
	private Map<String, String> fhdata;
	
	@RequestMapping(value="00017")
	@ResponseBody
	public ReturnBean AddBrabch(HttpSession hseesion){
		mReturn = new ReturnBean();
		fhdata = new HashMap<>();
		//传过来的参数
		String data =  (String) hseesion.getAttribute("data");
		PackNum00017 num00017 = JSON.parseObject(data,PackNum00017.class); 		
		if (data.equals(InterfaceDefinition.IStatusCode.TOKEN_FAILURE)) {//校验码错误
			mReturn.setCode("001");
			mReturn.setPortnum("00017");
			fhdata.put("error", "TOKEN_ERROR");
			mReturn.setData(JSON.toJSONString(fhdata));
		}else{
			ClientmessageBean entity = mClientMessage.selectByPrimaryKey((short) Integer.parseInt(num00017.getId()));
			entity.setCharge(num00017.getMoney());
			mClientMessage.updateByPrimaryKeySelective(entity);
			mReturn.setCode("000");
			mReturn.setPortnum("00017");
			fhdata.put("chenggong", "000");
			mReturn.setData(JSON.toJSONString(fhdata));
		}
		return mReturn;
	}
}
